package com.zl.service.impl;

import com.zl.dao.RoleprivilegeDao;
import com.zl.domain.Roleprivilege;
import com.zl.service.Role_PrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/5/5.
 */
@Service
public class Role_PrivilegeServiceImpl extends BaseServiceImpl<Roleprivilege> implements
        Role_PrivilegeService {
    @Autowired
    public RoleprivilegeDao role_privilegeDao;

    @Override
    public List<Roleprivilege> findByRId(int id) {
        return role_privilegeDao.findByRId(id);
    }

    @Override
    public int setPrivileges(String[] pids, int rid) {
        int ret = 0;
        Roleprivilege roleprivilege = new Roleprivilege();
        roleprivilege.setRid(rid);
        ret += role_privilegeDao.delete(roleprivilege);
        Roleprivilege role_privilege = new Roleprivilege();
        for (String pid : pids) {
            role_privilege.setPid(Integer.parseInt(pid));
            role_privilege.setRid(rid);
            ret += role_privilegeDao.insert(role_privilege);
        }
        return ret;
    }
}
